package com.cxrj.zhsq.workorderManage.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.cxrj.zhsq.workorderManage.entity.PropertyWorkorder;
import com.cxrj.zhsq.workorderManage.service.PropertyWorkorderService;

@RestController
public class PropertyWorkorderController {

	@Resource
	private PropertyWorkorderService propertyWorkorderService;

	/**
	 * 分页查询工单
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyWorkorders", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectPropertyWorkorders(HttpServletRequest request, HttpServletResponse response) {
		return propertyWorkorderService.seletePropertyWorkorderPage(request, response);
	}

	/**
	 * 根据id查询工单
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyWorkorderById", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> selectPropertyWorkorderById(String id, HttpServletRequest request) {
		return propertyWorkorderService.selectPropertyWorkorderById(id);
	}

	/**
	 * 添加工单
	 * 
	 * @return
	 */
	@RequestMapping(value = "insertPropertyWorkorder", method = RequestMethod.POST)
	public Map<String, Object> insertPropertyWorkorder(PropertyWorkorder propertyWorkorder, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			propertyWorkorder.setCommunityId(request.getSession().getAttribute("communityId").toString());
			resultMap = propertyWorkorderService.insertPropertyWorkorder(propertyWorkorder);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 修改工单
	 * 
	 * @return
	 */
	@RequestMapping(value = "updatePropertyWorkorder", method = RequestMethod.POST)
	public Map<String, Object> updatePropertyWorkorder(PropertyWorkorder propertyWorkorder, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = propertyWorkorderService.updatePropertyWorkorder(propertyWorkorder);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}
}
